import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:loading_animation_widget/loading_animation_widget.dart';
import 'package:winkai/entity/chat_msg.dart';
import 'package:winkai/entity/msg_constant.dart';
import 'package:winkai/ui/msg/widget/item/chat_msg_align_widget.dart';
import 'package:winkai/ui/msg/widget/item/chat_msg_bg_widget.dart';
import 'package:winkai/utils/image_utils.dart';
import 'package:winkai/utils/net_image_load_utils.dart';

class ChatMsgWaitWidget extends StatelessWidget {
  const ChatMsgWaitWidget({
    super.key,
    required this.message,
    this.onRetryClick,
    this.onAvatarClick,
  });

  final ChatMsg message;
  final void Function()? onRetryClick;
  final void Function()? onAvatarClick;

  @override
  Widget build(BuildContext context) {
    var isSend = message.isSend;
    var status = message.messageInfo.msg.status;
    var widget = ChatMsgBgWidget(
        padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 7.w),
        isSend: isSend,
        child: status == MsgStatus.failure
            ? ImageUtils.getImage('ic_ai_chat_tips_black', 24.w, 24.w)
            : LoadingAnimationWidget.waveDots(color: Colors.grey, size: 28.w));
    return ChatMsgAlignWidget(
      isSend: isSend,
      children: [
        if (!isSend)
          GestureDetector(
            onTap: () {
              onAvatarClick?.call();
            },
            child: NetImageLoadUtils.loadCircle(
                message.messageInfo.user?.avatar, 40.w),
          ),
        if (!isSend) SizedBox(width: 8.w),
        Flexible(
            child: status == MsgStatus.failure
                ? GestureDetector(
                    onTap: () {
                      onRetryClick?.call();
                    },
                    child: widget,
                  )
                : widget)
      ],
    );
  }
}
